package com.ruoyi.iot.config;

import java.util.ArrayList;
import java.util.List;

import org.apache.iotdb.session.pool.SessionPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;



/**
 * iotdb连接池
 */
@Component
@Configuration
public class IoTDBSessionPool {


    @Value("${spring.iotdb.username}")
    private String username;

    @Value("${spring.iotdb.password}")
    private String password;

    @Value("${spring.iotdb.url}")
    private String hostUrl;
    
    @Bean
    public SessionPool sessionPool() {
        List<String> nodeUrls = new ArrayList<>();
        nodeUrls.add(hostUrl);
        
        return new SessionPool.Builder()
                        .nodeUrls(nodeUrls)
                        .user(username)
                        .password(password)
                        .maxSize(10)
                        .build();
    }
}
